package com.cloudservice.ccs.config;

import jBCrypt.BCrypt;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.credential.CredentialsMatcher;

public class BcryptCredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
        String password = new String((char[]) authenticationToken.getCredentials());
        String correctAuthenticationString = (String) authenticationInfo.getCredentials();
        return BCrypt.checkpw(password, correctAuthenticationString);
    }
}
